package thread;

//创建MyRunnable02类，扩展Runnable接口，重写run()方法
//实现 Runnable, 重写 run
class MyRunnable02 implements Runnable{
    @Override
    public void run() {
        while(true){
            System.out.println("hello thread");
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class Demo02 {
    public static void main(String[] args) {
        //创建MyRunnable02对象
        Runnable runnable = new MyRunnable02();
        //将runnable对象作为参数创建一个线程对象
        Thread t = new Thread(runnable);
        //启动线程
        t.start();

        //主线程执行的任务
        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
